package com.cyy.dyeing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.cyy.dyeing.dto.MenuDto;
import com.cyy.dyeing.mapper.RoleMapper;
import com.cyy.dyeing.model.Role;
import com.cyy.dyeing.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: cyy
 * @Date: 2024/7/24
 */
@Service
@Slf4j
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;


    /**
     * 获取角色列表信息
     * @param u_id
     * @param code
     * @return
     */
    @Override
    public List<Role> findRoleList(String u_id, String code) {
        List<Role> list = roleMapper.findRoleList(u_id, code);
        return list;
    }

    @Override
    public void confirmRoleModules(Integer roId, Integer[] moduleIds) {
        //1. 删除指定角色的所有权限
        roleMapper.deleteRoleModules(roId);
        if(moduleIds == null || moduleIds.length == 0){
            return;
        }
        //2. 将提交的权限新增一遍
        for (Integer ids :moduleIds) {
            roleMapper.insertRoleModule(roId, ids);
        }

    }


}
